<?php

namespace App\Http\Controllers;

use App\Models\Server;
use App\Models\ServerV2;
use Exception;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Support\Facades\Auth;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    protected function CheckServer($id){
        $server=Server::find($id);
        $user=Auth::user();
        if ($user->is_admin==1 || $server->user_id==Auth::id()){
            if ($server->type===2)
                return ServerV2::find($id);
            return $server;
        }else{
            throw new Exception('无权访问次服务器',401);
        }
    }
}
